﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using VFramework;

namespace VFramework{

	/// <summary>
	/// 设置面板类,使用的时候继承该对象
	/// 默认带三个，音乐slide，音效slide，和背景灯光开光
	/// </summary>
	public class VUISettingWindow : VUIPopWindow {


		public Slider musicSlide;
		public Slider effectSlide;
		public Toggle lightToggle;


		protected override void _start(){
			
			if (_isStarted == false) {
				if (musicSlide != null)  {
					musicSlide.onValueChanged.AddListener (delegate(float arg0) {
						musicSlideChange(arg0);
					});
				}

				if (effectSlide != null) {
					effectSlide.onValueChanged.AddListener (delegate(float arg0) {
						effectSlideChange(arg0);	
					});
				}

				if (lightToggle != null) {
					lightToggle.onValueChanged.AddListener (delegate(bool arg0) {
						lightChange(arg0);	
					});
				}
			}

			base._start ();
		}


		public override void show ()
		{
			base.show ();
			if (musicSlide != null) {
				musicSlide.value = SystemMgr.getInstance ().getMusicValue ();
			}
			if (effectSlide != null) {
				effectSlide.value = SystemMgr.getInstance ().getEffectValue ();
			}
			if (lightToggle != null) {
				lightToggle.isOn = SystemMgr.getInstance ().getLightValue () == 1 ? true : false;
			}
		}

		protected virtual void musicSlideChange(float value){
			EventMgr.getInstance().dispatchEvent(FrameEvents.MUSIC_SLIDE_VALUE_CHANGE,value);
		}

		protected virtual void effectSlideChange(float value){
			EventMgr.getInstance().dispatchEvent(FrameEvents.EFFECT_SLIDE_VALUE_CHANGE,value);
		}

		protected virtual void lightChange(bool arg){
			EventMgr.getInstance().dispatchEvent(FrameEvents.LIGHT_TOGGLE_VALUE_CHANGE,arg);
		}
	}
}